﻿namespace DK.BinarySearch
{
    public class Sequence
    {
        int[] NumberArray;
        int first, mid, last;

        public Sequence(int[] array) 
        {
            NumberArray = array;
            first = 0;
            last = NumberArray.Length - 1;
            //mid = first + (last - first) / 2;
        }

        public int FindIndex(int number)
        {
            mid = first + (last - first) / 2;

            if (first >= last)
            {
                return -1;
            }
            else if(number > NumberArray[mid])
            {
                first = mid;
            }
            else if (number < NumberArray[mid])
            {
                last = mid;
            }
            else if (number == NumberArray[mid])
            {
                return mid;
            }
            
            return FindIndex(number);
        }

    }
}